package com.youboy.wechatapi.service.bind.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.youboy.wechatapi.domain.enums.BindType;
import com.youboy.wechatapi.domain.mysql.BindInfo;
import com.youboy.wechatapi.repository.message.BindRepository;
import com.youboy.wechatapi.service.bind.BindService;
import com.youboy.wechatapi.utils.page.PageUtils;

/**
 * @ProjectName：wechatapi
 * @author：冉尧（Yvan）
 * @CreateTime：2014年10月9日 下午4:06:36
 * @Remarks：
 */
@Service
public class BindServiceImpl implements BindService {

	@Autowired
	BindRepository bindRepository;

	@Override
	public void save(String openid, String us, BindType bindType) throws Exception {
		BindInfo bind = new BindInfo(openid, us, bindType);
		bindRepository.save(bind);
	}

	@Override
	public BindInfo getBindInfo(String openid) throws Exception {
		return bindRepository.getBindInfo(openid);
	}

	@Override
	public List<String> getBindInfo(Integer pageNo, Integer pageSize) throws Exception {
		int count = bindRepository.count();
		PageUtils<BindInfo> page = new PageUtils<BindInfo>(pageNo, pageSize, count);
		List<String> resultList = bindRepository.getUsPage(page.getFirstResult(), page.getPageSize());
		return resultList;
	}

}
